package com.atlassian.extras.common.log;

public class Logger {
    private static final Class<?> LOG4J_LOGGER_CLASS;

    private static Log logger;

    static {
        Class<?> log4jLogger = null;
        try {
            log4jLogger = Class.forName("com.atlassian.extras.common.log.Log4jLogger");
        } catch (ClassNotFoundException e) {

        } finally {
            LOG4J_LOGGER_CLASS = log4jLogger;
        }
    }

    public static interface Log {
        void setClass(Class param1Class);

        void debug(Object param1Object);

        void debug(Object param1Object, Throwable param1Throwable);

        void info(Object param1Object);

        void info(Object param1Object, Throwable param1Throwable);

        void warn(Object param1Object);

        void warn(Object param1Object, Throwable param1Throwable);

        void error(Object param1Object);

        void error(Object param1Object, Throwable param1Throwable);

        void fatal(Object param1Object);

        void fatal(Object param1Object, Throwable param1Throwable);
    }

    public enum Level {
        DEBUG, INFO, WARN, ERROR, FATAL;
    }

    private static Level stdErrLogLevel = Level.INFO;

    public static void setInstance(Log logger) {
        Logger.logger = logger;
    }

    public static Log getInstance(Class clazz) {
        if (logger != null) {
            return logger;
        }
        try {
            if (LOG4J_LOGGER_CLASS != null) {
                Log log4j = (Log)LOG4J_LOGGER_CLASS.newInstance();
                log4j.setClass(clazz);
                return log4j;
            }
        } catch (IllegalAccessException e) {

        } catch (InstantiationException e) {

        } catch (NoClassDefFoundError e) {}

        return null;
    }

    public static void setStdErrLogLevel(Level stdErrLogLevel) {
        if (stdErrLogLevel == null) {
            throw new IllegalArgumentException("StdErrLogger Log Level must not be null.");
        }
        Logger.stdErrLogLevel = stdErrLogLevel;
        logger = null;
    }
}
